package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantgspService;
import com.youi.entity.Merchantgap;
import com.youi.entity.Merchantgsp;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 药品经营质量管规范认证证书控制层
* @author Administrator
*/
@Controller
public class MerchantgspController  extends HttpRequestManage{

		@Autowired
		private MerchantgspService merchantgspService;

		/**
		 * I-71
		 * 添加或编辑药品经营质量管规范认证证书
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchantgsp")
		public String addOrEditMerchantgsp(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantgsp merchantgsp=merchantgspService.getByParam(prams);
			if (merchantgsp==null) {
				merchantgsp=new Merchantgsp();
				merchantgsp.setDelStatus(DelStatus.NODEL);
				merchantgsp.setGmtCreated(new Date());
				merchantgsp.setMerchantId(id);
			}
			String cardID=optString("cardID",request);
			if (cardID!=null){
				merchantgsp.setCardID(cardID);
			}
			String authScope=optString("authScope",request);
			if (authScope!=null){
				merchantgsp.setAuthScope(authScope);
			}
			String certificate=optString("certificate",request);
			if (certificate!=null){
				merchantgsp.setCertificate(certificate);
			}
			Date gmtValidity=optDate("gmtValidity", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtValidity!=null) {
				merchantgsp.setGmtValidity(gmtValidity);
			}
			merchantgsp.setGmtModify(new Date());
			merchantgspService.saveOrUpdate(merchantgsp);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}

		/**
		 * I-72
		 *  查询药品经营质量管规范认证证书
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantgspById")
		public String getMerchantgspById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantgsp merchantgsp=merchantgspService.getByParam(prams);
			if (merchantgsp==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantgsp);//jsonObject	json对象
		}

	
}
